var pageUtil = {
	setLocalStorage : function (key,name) {
		localStorage.setItem(key,name);
	},
	getLocalStorage : function (key) {
		return localStorage.getItem(key);
	},
	setCookie: function (key,name,time){
		var date = new Date();
		var expiresDays = time;
		date.setTime(date.getTime() + expiresDays * 3600 * 1000);//设置cookie存储的时间
		document.cookie = key + "=" + name + ";expires=" + date.toGMTString();
	},
	getCookie : function (key){
		var cookieArray = document.cookie.split("; "); //得到分割的cookie名值对 
		var cookie = new Object();
		for (var i = 0; i < cookieArray.length; i++) {
			var arr = cookieArray[i].split("="); //将名和值分开    
			if (arr[0] == key)
				return unescape(arr[1]); //如果是指定的cookie，则返回它的值
		}
		return "";
	},
	getArgForAutoLogin : function (key){
		var l = window.location.href;
		l = l.split('?')[1].split('#')[0];
		ary = l.split("&");
		for(var i = 0 ; i < ary.length ; i++){
			if(ary[i].split("=")[0]==key){
				return ary[i].split("=")[1];
			}
		}
		return '';
	},
	getUrl : function (name) {//获取url参数
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); 
		var r = window.location.search.substr(1).match(reg); 
		if (r != null) return unescape(r[2]); return null; 
	},
	getCookieMess : function (key) {//免登
		var userId = pageUtil.getCookie(key);
		var timeStamp = pageUtil.getCookie("timeStamp");
		var date = new Date();
		if(!userId || (date.getTime() - (eval(timeStamp)) > (3600*1000))){
			_dt.initConfig(_dt.nopassword,{});
		}
	},
	getArg : function (key) {
		var l = window.location.hash;
		l = l.split('?')[1];
		ary = l.split("&");
		for(var i = 0 ; i < ary.length ; i++){
			if(ary[i].split("=")[0]==key){
				return ary[i].split("=")[1];
			}
		}
		return '';
	},
	formatTime: function(time){
	    var _d=new Date(time);
	    return _d.getFullYear() + "-" +(_d.getMonth()+1<10?'0'+(_d.getMonth()+1):_d.getMonth()+1) + "-" + (_d.getDate()<10?'0'+(_d.getDate()):_d.getDate()) + " " + (_d.getHours()<10?'0'+(_d.getHours()):_d.getHours()) + ":" + (_d.getMinutes()<10?'0'+(_d.getMinutes()):_d.getMinutes()) + ":" + (_d.getSeconds()<10?'0'+(_d.getSeconds()):_d.getSeconds());
	}, 
    returnMeassage:function(str,word)
	{
	  var tips='';
	  for(var x in str)
	  {
	  	if(word)
	  	{
	  		tips=tips+''+x+' '+str[x]+word+',';
	  	}else{
	  		tips=tips+''+x+' '+str[x]+',';
	  	}
	  }
	  return tips.substr(0,tips.length-1);
	},
	returnArray:function(str){
		var d=[];
		for(var i=0;i<this.returnMeassage(str).split(',').length;i++)
		{
			d.push(
				{
				name:this.returnMeassage(str).split(',')[i].split(' ')[0],
				value:parseInt(this.returnMeassage(str).split(',')[i].split(' ')[1])
				}
			);
		}
		return d;
	},
	traverse:function(ary,backcall){
	    ary.map(function(item,index){
	      backcall(item,index);
	    });
	},
  	isArray:function(ary){
    	return Object.prototype.toString.call(ary) === '[object Array]';
    },
    IsLeaf:function(treeNode)
    {
    	// var tree=treeNode.filter((item,index)=>{
    	// 	return !item.isLeaf;
    	// })
    	var tree=[];
    	treeNode.map(function(item,index){
    		if(!item.isLeaf){
    			tree.push(item);
    		}
    	})
    	if(tree.length){
    		return true;
    	}else{
    		return false;
    	}
    },
    delay:function(timeout){
	  var pro = new Promise(function(resolve,reject){
	    setTimeout(resolve, timeout);
	  });
	  return pro;
	}
}

